<template>
  <div>
    <a-breadcrumb class="breadcrumb">
      <a-breadcrumb-item v-for="(item, index) in breadList" :key="item.name">
        <router-link v-if="item.name != name && index != 1" :to="{ path: item.path === '' ? '/' : item.path }">{{
          $t(item.meta.title)
        }}</router-link>
        <span v-else>{{ $t(item.meta.title) }}</span>
      </a-breadcrumb-item>
    </a-breadcrumb>
    <div v-if="backNavigation">
      <a-button type="primary" @click="backNavigation.onBack">
        <a-icon type="left" />
        {{ backNavigation.title || $t('common.back') }}</a-button
      >
    </div>
  </div>
</template>

<script>
export default {
  props: {
    backNavigation: {
      type: Object,
      default: null,
      required: false
    }
  },
  data() {
    return {
      name: '',
      breadList: []
    };
  },
  created() {
    this.getBreadcrumb();
  },
  methods: {
    getBreadcrumb() {
      this.breadList = [];
      // this.breadList.push({name: 'index', path: '/dashboard/', meta: {title: '首页'}})

      this.name = this.$route.name;
      this.$route.matched.forEach(item => {
        // item.name !== 'index' && this.breadList.push(item)
        this.breadList.push(item);
      });
    }
  },
  watch: {
    $route() {
      this.getBreadcrumb();
    }
  }
};
</script>

<style scoped>
.breadcrumb {
  margin-bottom: 16px;
}
.back-navigation {
  padding: 0;
  margin-bottom: 16px;
}
</style>
